﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gtkj.CMS.BLL
{
   public class HomeBll
    {
        public List<string> GetNames(string sessionid,string dbname)
        {
           string  str = string.Format("select FLD_NAME from TBL_XWWL_Char where FLD_ID='{0}'", sessionid);
            SQLHelperBll sQLHelperBll = new SQLHelperBll(dbname);
            DataTable dataTable = sQLHelperBll.ExecuteDataTable(str, null, ref str, 0);
            List<string> strs = new List<string>();
            if (dataTable != null)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    strs.Add(row[0].ToString());
                }
            }
            return strs;
        }

        public int CheckUserName(string sessionid,string username,string dbname)
        {
            SQLHelperBll sQLHelperBll = new SQLHelperBll(dbname);
            string str = string.Format("select count(1) from TBL_XWWL_Char where FLD_ID='{0}' and FLD_NAME='{1}'",sessionid, username);
            return Convert.ToInt32(sQLHelperBll.ExecuteScalar(str, null, ref str, 0));
        }

        public int CheckZhuansheng(string username,string dbname)
        {
            
           string  sqlstr = string.Format("select FLD_ZS FROM TBL_XWWL_Char where FLD_NAME='{0}'", username);
            SQLHelperBll sQLHelperBll = new SQLHelperBll(dbname);
            int resu = (int)sQLHelperBll.ExecuteScalar(sqlstr, null, ref sqlstr);
            return resu;
        }

        public List<string> GetYuanBao(string sessionid,string dbname)
        {
            SQLHelperBll sQLHelperBll = new SQLHelperBll(dbname);
            string sqlstr = string.Format("SELECT FLD_RXPIONT,FLD_RXPIONTX from TBL_ACCOUNT WHERE FLD_ID='{0}'", sessionid);
            string msg = "";
            var resu = sQLHelperBll.ExecuteDataTable(sqlstr, null, ref msg);
            List<string> list = new List<string>();
            list.Add(resu.Rows[0]["FLD_RXPIONT"].ToString());
            list.Add(resu.Rows[0]["FLD_RXPIONTX"].ToString());
            return list;
        }

        public int CheckUser(string id,string password,string dbname)
        {
            SQLHelperBll sQLHelperBll = new SQLHelperBll(dbname);
            string msg = "";
           return  Convert.ToInt32(sQLHelperBll.ExecuteScalar(string.Format("select count(1) from TBL_ACCOUNT where FLD_ID='{0}' and FLD_PASSWORD='{1}'", id, password), null, ref msg, 0));
        }

        public int CutYuanBao(string sessionid,int number,string dbname)
        {
            SQLHelperBll sQLHelperBll = new SQLHelperBll(dbname);
           string sqlstr = string.Format("UPDATE TBL_ACCOUNT SET FLD_RXPIONTX='{0}' where FLD_ID = '{1}'", number, sessionid);
            return sQLHelperBll.ExecuteNonQuery(sqlstr, null, ref sqlstr);
        }
    }
}

